package com.cn.yunhe.mybatis.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cn.yunhe.mybatis.dao.UserMapper;
import com.cn.yunhe.mybatis.model.Page;
import com.cn.yunhe.mybatis.model.UserModel;
import com.cn.yunhe.mybatis.service.IUserService;
@Service("userService")
public class UserServiceImpl implements IUserService{
	@Autowired
private UserMapper userMapper;

	@Override
	public UserModel findUser(UserModel user) {
		// TODO Auto-generated method stub
		
		return userMapper.findUser(user);
	}
	@Override
	public UserModel getUser(UserModel user) {
		// TODO Auto-generated method stub
		return userMapper.getUser(user);
	}
	@Override
	public void insert(UserModel user) {
		// TODO Auto-generated method stub
		userMapper.insert(user);
		
	}

	@Override
	public void update(UserModel user) {
		// TODO Auto-generated method stub
		userMapper.update(user);
	}
	
	@Override
	public void delete(UserModel user) {
		// TODO Auto-generated method stub
		userMapper.delete(user);
	}

	@Override
	public Page getUserList(Map<String, Object> pList) {
		// TODO Auto-generated method stub
		Page page =new Page();
		int pageSize=Integer.parseInt(String.valueOf(pList.get("pageSize")));//request的值
	    int curPageNum=Integer.parseInt(String.valueOf(pList.get("pageNum")));//request的值
		page.setTotalNum(userMapper.getUserListCount(pList));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		//三元运算法，总记录数对页的大小求余是否等于0（如果为0：+0  否则+1） 比如getTotalNum（13）   pageSize（4）
		page.setResult(userMapper.getUserList(pList));
		return page;
	}

	

	
	
}